import { create } from 'zustand'

import { ChatText, RoleItem } from '@/service/models/ChatModel'

interface ChatState {
  roleList: RoleItem[]
  messageList: ChatText[]
  currentRoleId: string
  currentIndex: number
}

interface ChatAction {
  addRole: (role) => void
  addMessage: (message: ChatText) => void
}

export const useChatStore = create<ChatState & ChatAction>()(set => ({
  roleList: [],
  messageList: [],
  currentRoleId: '0',
  currentIndex: 0,

  addRole: role => set(state => ({ roleList: [...state.roleList, role] })),
  addMessage: message => {
    return set(state => {
      return {
        messageList: [...state.messageList, message],
      }
    })
  },
}))
